package com.example.jsonformateapplication.controller;

import com.example.jsonformateapplication.dao.UserDao;
import com.example.jsonformateapplication.entity.ApiResponseDate;
import com.example.jsonformateapplication.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 胡新毅 乐武护
 * @since 2024/9/14
 */
@RestController
@RequestMapping("/user")
public class UserController {
    private int id;

    @GetMapping("/list")
    public ApiResponseDate getAll(){
        Map<Integer, User> list= UserDao.getAll();
        return new ApiResponseDate("200","用户列表获取成功",true,list);
    }
    @GetMapping("/{id}")
    public ApiResponseDate getByid(@PathVariable int id){
        User obj=UserDao.getByid(id);
        return new ApiResponseDate("200","用户列表获取成功",true,obj);
    }
    @PostMapping("/add")
    public ApiResponseDate add(@RequestBody User user){
        UserDao.add(user);
        return new ApiResponseDate("200","新加成功",true,user);
    }
    @PutMapping("/update")
    public ApiResponseDate update(@RequestBody User user){
        UserDao.update(user);
        return new ApiResponseDate("200","修改成功",true,user);
    }
    @DeleteMapping("/delete/{id}")
    public ApiResponseDate delete(@RequestBody User user){
        UserDao.delete(id);
        return new ApiResponseDate("200","删除成功",true,null);
    }



}

